package Fenetre;

import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class ProgressPanel extends JPanel {

	private static final long serialVersionUID = -8574655232713708034L;

	private ArrayList<JLabel> labels = new ArrayList<JLabel>();
	private ArrayList<JProgressBar> progress = new ArrayList<JProgressBar>();

	public static final int LECTURE = 0;
	public static final int CREATION_BASE = 1;
	public static final int CREATION_TYPE = 2;
	public static final int CREATION_MODELE = 3;
	public static final int INSERTION_CONSTANTES = 4;
	public static final int INSERTION_ATOMES= 5;
	public static final int COMTAGE=6;
	public static final int GENERATION_GRAPHE = 7;
	public static final int VARIABILISATION = 8;

	public ProgressPanel(){
		ajouterObjetsGraphiques();
		
		this.setLayout(new GridLayout(labels.size(),1));
		
		for(int i=0;i<labels.size();++i){
			this.add(labels.get(i));
			this.add(progress.get(i));
		}
		
	}

	private void ajouterObjetsGraphiques(){
		
		labels.add(new JLabel("Lecture des fichers d'entrée "));
		labels.add(new JLabel("Création de la base de données "));
		labels.add(new JLabel("Création des tables types "));
		labels.add(new JLabel("Création des tables modèles "));
		labels.add(new JLabel("Insertion des constantes "));
		labels.add(new JLabel("Insertion des atomes "));
		labels.add(new JLabel("Comptage "));
		labels.add(new JLabel("Generation du graphe "));
		labels.add(new JLabel("Variabilisation "));

		for(int i=0;i<labels.size();++i){
			JProgressBar p = new JProgressBar(0,100);
			p.setStringPainted(true);
			progress.add(p);
		}
			
	}

	public void setProgressValue(int etape, int value) {
		if(etape<progress.size()){
			JProgressBar p = progress.get(etape);
			if(p.getValue()!=value)
				p.setValue(value);
		}
	}

	public void vider() {
		for(int i=0;i<progress.size();++i){
			progress.get(i).setValue(0);
		}
		
	}

}
